/**
 * Copyright (c) 2012 Nokia Corporation.
 * All rights reserved.
 *
 * For the applicable distribution terms see the license text file included in
 * the distribution.
 */

import QtQuick 1.1
import com.nokia.symbian 1.1

Page {
    id: placesListPage

    Component {
        id: listHeading

        ListHeading {
            width: parent.width

            ListItemText {
                anchors.fill: parent.paddingItem
                role: "Heading"

                text: {
                    var headingText = "No places found";

                    if (listView.count == 1) {
                        headingText = "Found 1 place";
                    }
                    else if (listView.count > 1) {
                        headingText = "Found " + listView.count + " places";
                    }

                    return headingText;
                }
            }
        }
    }

    Component {
        id: listDelegate

        ListItem {
            id: listItem
            subItemIndicator: true

            Column {
                anchors.fill: listItem.paddingItem

                ListItemText {
                    id: titleText
                    width: parent.width
                    mode: listItem.mode
                    role: "Title"
                    text: placename
                }
                ListItemText {
                    id: subtitleText
                    width: parent.width
                    mode: listItem.mode
                    role: "SubTitle"
                    text: placeaddress
                }
            }

            onClicked: {
                // Hide the search bar if visible.
                filterBar.hide();
                pageStack.push("qrc:/PlacesDetailPage.qml",
                               { placeId: placeid });
            }
        }
    }

    ListView {
        id: listView

        y: filterBar.state == "shown" ? filterBar.height : 0;
        width: parent.width
        height: filterBar.state == "shown" ? parent.height - filterBar.height
                                           : parent.height;

        anchors {
            left: parent.left
            right: parent.right
        }

        model: placesListModel
        delegate: listDelegate
        header: listHeading
        focus: true
        clip: true

        Behavior on y {
            SmoothedAnimation {}
        }
    }
    ScrollDecorator {
        flickableItem: listView
    }
}
